package com.guli.teacher.controller.front;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.guli.common.result.Result;
import com.guli.teacher.entity.EduCourse;
import com.guli.teacher.entity.EduTeacher;
import com.guli.teacher.service.EduCourseService;
import com.guli.teacher.service.EduTeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/frontteacher")
@CrossOrigin
public class FrontTeacherController {

    @Autowired
    private EduTeacherService teacherService;

    @Autowired
    private EduCourseService courseService;

    // 讲师列表分页功能
    @GetMapping("findAllTeacherFront/{page}/{limit}")
    public Result getAllTeacherFront(@PathVariable Long page,
                                     @PathVariable Long limit){
        // 1 创建一个page对象
        Page<EduTeacher> pageTeacher = new Page<>(page,limit);
        // 2 调用service方法实现分页
        // 把分页的所有数据封装到map中去，返回map集合
        Map<String,Object> map = teacherService.getTeacherAllFront(pageTeacher);

        return  Result.ok().data(map);
    }

    /**
     * 根据讲师id查询讲师详情
     */
    @GetMapping("getFrontTeacherInfo/{id}")
    public Result getFrontTeacherInfo(@PathVariable String id){
        // 1 根据讲师id查询讲师信息
        EduTeacher teacherInfo = teacherService.getById(id);

        // 2 根据讲师id查询讲师所讲课程
        List<EduCourse> courseList = courseService.getCouseListTeacherId(id);

            return Result.ok().data("teacherInfo", teacherInfo).data("courseList", courseList);

    }

}
